<?php
/**
 * Joomla! 1.5 component JoomGPSTracks
 *
 * @version $Id: download.php 2009-06-24 15:40:19 svn $
 * @author Michael Pfister
 * @package joomGPStracks
 * @subpackage frontend
 * @license GNU/GPL
 * @filesource
 *
 */


// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.controller' );

class JoomgpstracksControllerDownload extends JoomgpstracksController  {

    function download()  {

        JRequest::checkToken() or jexit( 'Invalid Token' );

        $format =& JRequest::getVar('format');
        $model = $this->getModel('download');
        $id =& JRequest::getInt('id');
        $track = $model->getTrack($id);
        $trackname = str_replace(' ', '_', $track->title);
        if($format == "kml")  {
            $mime = "application/vnd.google-earth.kml+xml";
        } else {
            $mime = "application/x-octet-stream";
        }

        header("Content-Type: ".$mime."");
        header("Content-Disposition: attachment; filename=".$trackname.".".strtolower($format));
        header("Content Transfer-Encoding:binary");
        header("Cache-Control: post-check=0, pre-check=0");

        
        echo $model->download($id, $format, $track);

    }
    
}
?>
